﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class cms_ListUserInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Response.Redirect("Default.aspx");
        }
        if (!IsPostBack)
        {
            DataRow dr = (DataRow)Session["user"];
            hplAddNewUser.Visible = Convert.ToBoolean(dr["IsAdmin"]);
            GVUserInfo.Columns[10].Visible = Convert.ToBoolean(dr["IsAdmin"]);
            GVUserInfo.Columns[11].Visible = Convert.ToBoolean(dr["IsAdmin"]);
        }
    }
    protected void GVUserInfo_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        DBClass db = new DBClass();
        switch (e.CommandName)
        {
            case "Edit":
                Response.Redirect("AddNewUserInfo.aspx?Id=" + Convert.ToInt32(e.CommandArgument));
                break;
            case "Delete":
                DataRow dr = (DataRow)Session["user"];
                if (Convert.ToInt32(e.CommandArgument) != Convert.ToInt32(dr["Id"]))
                {
                    db.DeleteUserInfo(Convert.ToInt32(e.CommandArgument));
                }
                else
                {
                    Response.Write("<script>alert('No delete user because user info = user login.')</script>");
                }
                break;
            default:
                break;
        }
        Response.Redirect("ListUserInfo.aspx");
    }
}